package com.example.dryyzx.dao;

import com.example.dryyzx.entity.User;
import org.apache.ibatis.jdbc.SQL;

public class UserSqlProvider {
    public String insertSelective(User record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("user");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getName() != null) {
            sql.VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getSex() != null) {
            sql.VALUES("sex", "#{sex,jdbcType=CHAR}");
        }
        
        if (record.getAge() != null) {
            sql.VALUES("age", "#{age,jdbcType=INTEGER}");
        }
        
        if (record.getPhone() != null) {
            sql.VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }
        
        if (record.getJob() != null) {
            sql.VALUES("job", "#{job,jdbcType=CHAR}");
        }
        
        if (record.getSalary() != null) {
            sql.VALUES("salary", "#{salary,jdbcType=INTEGER}");
        }
        
        if (record.getEmployeeNumber() != null) {
            sql.VALUES("employee_number", "#{employeeNumber,jdbcType=VARCHAR}");
        }
        
        if (record.getRemarks() != null) {
            sql.VALUES("remarks", "#{remarks,jdbcType=VARCHAR}");
        }
        
        if (record.getEntryTime() != null) {
            sql.VALUES("entry_time", "#{entryTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getIsLeaving() != null) {
            sql.VALUES("is_leaving", "#{isLeaving,jdbcType=BIT}");
        }
        
        if (record.getLeavingTime() != null) {
            sql.VALUES("leaving_time", "#{leavingTime,jdbcType=TIMESTAMP}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(User record) {
        SQL sql = new SQL();
        sql.UPDATE("user");
        
        if (record.getName() != null) {
            sql.SET("name = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getSex() != null) {
            sql.SET("sex = #{sex,jdbcType=CHAR}");
        }
        
        if (record.getAge() != null) {
            sql.SET("age = #{age,jdbcType=INTEGER}");
        }
        
        if (record.getPhone() != null) {
            sql.SET("phone = #{phone,jdbcType=VARCHAR}");
        }
        
        if (record.getJob() != null) {
            sql.SET("job = #{job,jdbcType=CHAR}");
        }
        
        if (record.getSalary() != null) {
            sql.SET("salary = #{salary,jdbcType=INTEGER}");
        }
        
        if (record.getEmployeeNumber() != null) {
            sql.SET("employee_number = #{employeeNumber,jdbcType=VARCHAR}");
        }
        
        if (record.getRemarks() != null) {
            sql.SET("remarks = #{remarks,jdbcType=VARCHAR}");
        }
        
        if (record.getEntryTime() != null) {
            sql.SET("entry_time = #{entryTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getIsLeaving() != null) {
            sql.SET("is_leaving = #{isLeaving,jdbcType=BIT}");
        }
        
        if (record.getLeavingTime() != null) {
            sql.SET("leaving_time = #{leavingTime,jdbcType=TIMESTAMP}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}